#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <fcntl.h>

int main(int argc, char const *argv[])
{
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);

    int bufsize;
    int len = sizeof(bufsize);
    getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &bufsize, &len);
    printf("初始的发送缓冲区大小：%d\n", bufsize);

    bufsize = 1024;
    setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &bufsize, sizeof(int));

    bufsize = 0;
    getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &bufsize, &len);
    printf("设置后发送缓冲区大小：%d\n", bufsize);


    
    struct sockaddr_in addr;
    len = sizeof(addr);
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = inet_addr("192.168.31.128");
    addr.sin_port = htons(50006);

    if(connect(sockfd, (struct sockaddr*)&addr, len) == -1)
    {
        perror("connect() failed");
        exit(0);
    }

    int m = write(sockfd, "abcd\n", 5); // 普通数据
    if(m == -1)
    {
        perror("write() failed");
        exit(0);
    }

    pause();
    close(sockfd);

    return 0;
}
